<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="portal" uri="/WEB-INF/portal.tld" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/plateform/include/common-base.jsp"%>
  <title>管理员设置管理</title>
  <!-- Tell the browser to be responsive to screen width -->
</head>

<!-- Part 一、 以下是body主体内容的模块区域 -->
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

  <!-- top start -->
  <%@include file="/common/plateform/top.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/plateform/left-project.jsp" %>
  <!-- left end-->

  <div class="content-wrapper">
    <!-- Main start -->
	<section class="content">
	  			<div id="div_hidden_content" class="hidden" style="display:none;">
			  					<div id="hidden_common_final">
									<!-- temp="hidden_common_final" start -->
										<input name="mainObjName" type="hidden" value="uctUser">
										<input name="mainObjPrimaryKey" type="hidden" value="userId">
										<input name="objNameAll" type="hidden" value="uctUser">
				<!-- temp="hidden_common_final" end -->
								 </div>
			 					<!-- temp="delForm_hidden" start -->
									<div id="delForm_hidden">
									</div>
								<!-- temp="delForm_hidden" end -->
	  			</div>
      <div class="row">
        <div class="col-xs-12">
        
          <!------搜索  start ------->
          <div class="box box-info">
             <!--搜索title  start --> 
	          <div class="box-header with-border">
                 <h3 class="box-title"><i class="fa fa-search"></i> 系统管理员搜索</h3>
                 <div class="box-tools pull-right">
    				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
 				 </div>
              </div>
            <!--搜索title  end --> 
            <div class="box-body">
            	<form id="searchForm" action="javascript:;">
	            	<!-- temp="searchForm_hidden" start -->
	            	<div id="searchForm_hidden">
						<input type="hidden" name="pageName" value="uct-user-sys-list"/>
						<input type="hidden" name="formName" value="searchForm"/>
						<input type="hidden" name="uctUserSys.w_sysNo" value=""/>
						<input type="hidden" name="orderBy" value="uctUserSys.create_time desc"/>
					</div>
					<!-- temp="searchForm_hidden" end -->
					
	              	<!-- temp="searchForm_content" start -->
				<div id="searchForm_content" class="form-group"  data-temp-code="true" data-temp-type="searchForm" data-temp-form-id="searchForm">

					<table class="table table-bordered bordercolor">
						<tbody>
						<tr>
							<td class="active" align="right"><label class="form-control-static">登录账号：</label></td>
							<td>
								<div class="form-group"><input name="uctUser.wl_userEname" class="form-control clean"
															   maxlength="30" data-temp-obj="uctUser.userEname"></div>
							</td>
							<td class="active" align="right"><label class="form-control-static">用户名称：</label></td>
							<td>
								<div class="form-group"><input name="uctUser.wl_userCname" class="form-control clean"
															   maxlength="30" data-temp-obj="uctUser.userCname"></div>
							</td>
						</tr>
						</tbody>
					</table>
				</div>
				<!-- temp="searchForm_content" end -->
			  	</form>
			  <div class="box-footer text-center">
			       <button type="button" class="btn btn-success" onclick="getTableData();" data-temp-event="searchForm_hidden"><i class="fa fa-search"></i> 查询</button> 
			       <button type="button" class="btn btn-warning" onclick="mytools.cleanData('#searchForm');">重置 </button>
			   </div>
            </div>
	     </div>
	     <!------- 搜索 end -------->
           
        <!------- 列表 start -------->
          <div class="box box-success">
            <!--列表title  start --> 
	          <div class="box-header with-border">
                 <h3 class="box-title"><i class="fa fa-table"></i> 查询结果 
                 　　　              <button id="button_to_add" onclick="toAdd();" class="btn btn-success" type="button"><i class="fa fa-plus-circle"></i> 添加系统管理员 </button>
                 </h3>
                 <div class="box-tools pull-right">
    				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
 				 </div>
              </div>
			  <div class="box-body">
              	 	<table id="dataList" class="table table-bordered table-hover">
              	 		<thead class="bg-success">
		                	<tr id="dataList_thead_content" data-temp-code="true" data-temp-type="table" data-temp-show="dataList_template_content">
			                	<th>序号</th>
			                	<!-- temp="dataList_thead_content" start -->

											<th data-temp-obj="uctUserSys.userEname">登录账号</th>
											<th data-temp-obj="uctUser.userCname">用户名称</th>
											<th data-temp-obj="uctUser.delStatus">用户类别</th>
											<th data-temp-obj="uctUser.mobile">手机</th>
											<th data-temp-obj="uctUserSys.createTime">添加时间</th>
											<th data-temp-obj="uctUser.userStatus">状态</th>
											<th>操作</th>
				<!-- temp="dataList_thead_content" end -->
		                	</tr>
	                	</thead>
		                <tbody id="dataList-body">
		                	
		                </tbody>
	              </table>
            	</div>
           	 	
           	 	<div class="box-footer text-center">
			      	<ul id="dataList-page" class="pagination">
					</ul>
			 	</div>              
           </div>
        <!------- 列表 end -------->
        </div>
      </div>
  
<div win-title="添加窗口" class="modal fade" id="my_modal_add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:80%;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							×
						</button>
						<h4 class="modal-title">
							<font color="red">管理员选择窗口</font>&nbsp;<font class="red f12">[可选择用户类别：机构管理员、系统管理员]</font>
						</h4>
					</div>

					<div class="modal-body">
						
					       <div class="nav-tabs-custom">
					            <ul class="nav nav-tabs" id="myTab-add">
					            </ul>
					              
					            <!-- tab content start -->
					            <div class="tab-content">
					            	<form id="user-dataList-form" action="javascript:;">
										<input type="hidden" name="pageName" value="user-list"/>
										<input type="hidden" name="formName" value="searchForm-new"/>
										<input type="hidden" name="uctUser.w_userType" value="manager"/>
										<!--
										<input type="hidden" name="uctUser.w_customerType" value="person"/>
										-->
										<c:if test="${loginUser.user.customerType =='org'}">
											<input type="hidden" name="uctUser.w_orgId" value="${loginUser.orgId}"/>
										</c:if>
										<c:if test="${loginUser.user.customerType =='person'}">
											<input type="hidden" name="uctUser.w_userEname" value="${loginUser.userEname}"/>
										</c:if>
										<input type="hidden" name="orderBy" value="uctUser.create_time desc"/>
									</form>
					               <div class="tab-pane active" id="tabAdd_1">
									   <table id="user-dataList" class="table table-bordered table-hover">
										   <thead>
										   <tr >
											   <th>序号</th>
											   <th data-temp-obj="uctUser.userEname">登录账号</th>
											   <th data-temp-obj="uctUser.userCname">用户名称</th>
											   <th data-temp-obj="uctUser.email">用户类别</th>
											   <th data-temp-obj="uctUser.createTime">创建时间</th>
											   <th data-temp-obj="uctUser.userStatus">状态</th>
											   <th>选用操作</th>
										   </tr>
										   </thead>
										   <tbody id="user-dataList-body">

										   </tbody>
									   </table>
									   <div class="box-footer text-center">
										   <ul id="user-dataList-page" class="pagination">
										   </ul>
									   </div>
					               </div>


								</div>
					            <!-- tab content e -->
				          </div>	
			                
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>  



<!-- Part 二、以下是template模板定义的模块区域 -->
<script type="text/template" id="dataList-template">
		<? for ( var i = 0; i < rows.length; i++) {?>
		<tr>
				<td><?=(pageObj.currentPage-1)*10+(i+1)?></td>
			<!-- temp="dataList_template_content" start -->
				<td style='display:none;'><input type="hidden" name="input_primaryKey" obj-name="uctUserSys" primary="infoId" value="<?=strUtil.doNull(rows[i].uctUserSys.infoId,'')?>"/></td>
				<td><?=strUtil.doNull(rows[i].uctUserSys.userEname,'')?></td>
				<td><?=strUtil.doNull(rows[i].uctUser.userCname,'')?></td>
				<td>
					<?if(rows[i].uctUser.delStatus=='0'){?>机构用户<?}?>
					<?if(rows[i].uctUser.delStatus=='2'){?>机构管理员<?}?>
					<?if(rows[i].uctUser.delStatus=='3'){?>系统管理员<?}?>
				</td>
				<td><?=strUtil.doNull(rows[i].uctUser.mobile,'')?></td>
				<td><?=getFormatDateByLong(rows[i].uctUserSys.createTime,'yyyy-MM-dd hh:mm:ss')?></td>
				<td>
					<?if(rows[i].uctUser.userStatus=='1'){?>
					<span class="text-green">启用中</span>
					<?}?>
					<?if(rows[i].uctUser.userStatus=='0'){?>
					<span class="text-red">已停用</span>
					<?}?>
				</td>
				<!-- temp="dataList_template_content" end -->
              <td>
				<button type="button" class="btn btn-danger btn-xs" onclick="toDeleUserSys(this);"><i class="fa fa-trash-o"></i> 删除</button>  

			</td>
		</tr>
   <?}?>  		
</script>

<script type="text/template" id="user-dataList-template">
	<? for ( var i = 0; i < rows.length; i++) {?>
	<tr>
		<td><?=(pageObj.currentPage-1)*10+(i+1)?></td>
		<td><?=strUtil.doNull(rows[i].uctUser.userEname,'')?></td>
		<td><?=strUtil.doNull(rows[i].uctUser.userCname,'')?></td>
		<td>
			<?if(rows[i].uctUser.delStatus=='0'){?>机构用户<?}?>
			<?if(rows[i].uctUser.delStatus=='2'){?>机构管理员<?}?>
			<?if(rows[i].uctUser.delStatus=='3'){?>系统管理员<?}?>
		</td>
		<td><?=getFormatDateByLong(rows[i].uctUser.createTime,'yyyy-MM-dd hh:mm:ss')?></td>
		<td>
			<?if(rows[i].uctUser.userStatus=='1'){?>
			<span class="text-green">启用中</span>
			<?}?>
			<?if(rows[i].uctUser.userStatus=='0'){?>
			<span class="text-red">已停用</span>
			<?}?>
		</td>
		<td>
			<input type="radio" value="<?=rows[i].uctUser.userId?>"
				   user-id="<?=rows[i].uctUser.userId?>" user-ename="<?=rows[i].uctUser.userEname?>"
				   onclick="addUserSysData(this)" name="check-radio-userinfo"/> 选用
		</td>
	</tr>
	<?}?>
</script>

		<!-- Part 三、 以下是js模块区域 -->
<script>
var clickMenu = "user-list";
var myPage,dataListId,searchFormId;
myPage = 10;//定义列表数据
dataListId = "dataList";//显示列表数据div的id
searchFormId = "searchForm";//搜索表单Id
var defSysEname = strUtil.doNull(strUtil.getLocalStorage("sysEname"), "");
/**
 * 初始化数据字典，id传入#id 返回值Map用法：dictListMap["userType"][rows[i].userType]
 */
var dictListMap = DictUtil.initDictAndDymic();

$(function () {
    if (!strUtil.isNull(defSysEname)) {
        $("#searchForm_hidden").find("input[name='uctUserSys.w_sysNo']").val(defSysEname);
    }
//1、加载分页列表数据

    getTableData();
	
	//2、控制是否启用token
	//setToken();
	
 });
 
 $(function () {
	//设置数据行选中效果
	$('#'+dataListId+' tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	        }
	        else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	     //var id = $('tr.selected th').eq(0).html();
	} );
 });
//注入日历框样式
var dateObject = $('.datepicker').datepicker( {
	language : 'zh-CN',
	//inline: true,
	todayBtn : "linked",
	format : "yyyy-mm-dd",
	autoclose: true
}).on('hide',function(e) {
	//bootstrap datepicker与bootstrapValidator同时使用时选择日期后无法正常触发校验的解决方法
	//当日期选择框关闭时，执行刷新校验。
	var fieldName = $(this).attr("name");//获取当前元素name
	var formId = $(this).parents("form").eq(0).attr("id");//获取当前元素所在父层级中的就近的formId
    $("#"+formId).data('bootstrapValidator').updateStatus(fieldName,'NOT_VALIDATED',null).validateField(fieldName);
});

//给模态窗口内form表单内的所有支持必填项的元素注入校验
$(".modal").on('shown.bs.modal', function () {
	$(this).find("form").each(function(){
		var formId = $(this).attr("id");
		if(!strUtil.isNull(formId)){
			formId="#"+formId;
		 	setValidate(formId);//定义add表单验证属性
			mytools.cleanValidate(formId);//清空上次校验规则提示
		}
	});
});

//打开添加modal
function toAdd(){
	mytools.cleanData(".addFormBody");//清空表单元素上次填写的内容；
	$("#my_modal_add").modal("show");
    $.ajax({
        type:'get',
        url:common_list_url,
        data:$("#user-dataList-form").serialize()+getCurrentPage(common_list_url+"?"+$("#user-dataList-form").serialize(),myPage),
        dataType:'json',
        success: function(myData){
            console.log(myData);
            var data = baidu.template("user-dataList-template",eval(myData));
            $("#user-dataList-body").html(data);
            var option= {
                ele:$("#user-dataList-page")[0],
                total:myData.total,
                fn:getTableData,
                url:common_list_url+"?"+$("#user-dataList-form").serialize()
            }
            generatePages(option);
        }
    });
}

//删除调用
function toDeleUserSys(obj){
	var index_submit = layer.confirm("您确定要删除信息吗？", {btn: ["Yes","No"],closeBtn: 0,offset: "220px"}
	, function(){
		layer.close(index_submit);
		var paramData = {};
		var inputPrimaryObj = $(obj).parent().parent().find("input[name='input_primaryKey']");
		paramData["modelTypes"]="d_uctUserSys";
		if(inputPrimaryObj.length>0){
            for(var k=0;k<inputPrimaryObj.length;k++){
                var pkobj=$(inputPrimaryObj[k]);
                paramData[pkobj.attr("obj-name")+".w_"+pkobj.attr("primary")]=pkobj.val();
            }
			$.ajax({
		    	type:"post",
		    	url:common_submit_url,
		    	data: paramData,dataType:"json",
		    	success: function(myData){
		    		var result = myData.flag;
		    		if(result=="T"){
		    			refresh();
		    		}else{
		    			layer.alert("删除失败！");
		    		}
		  		}
			});
		}
	});
}

//加载列表数据
function getTableData(){
	$.ajax({
		   type:'get',
		   url:common_list_url,
		   data:$("#"+searchFormId).serialize()+getCurrentPage(common_list_url+"?"+$("#"+searchFormId).serialize(),myPage),
		   dataType:'json',
		   success: function(myData){
		   	console.log(myData);
			    var data = baidu.template(dataListId+"-template",eval(myData));  
				$("#"+dataListId+"-body").html(data);
				  var option= {
						   ele:$("#"+dataListId+"-page")[0],
						   total:myData.total,
						   fn:getTableData,
						   url:common_list_url+"?"+$("#"+searchFormId).serialize()
					   }
					generatePages(option);
			   }
		});	
  }


//提交tab1表单数据
function submitForm1(formId,tabId){
	//校验规则-表单提交时触发
	var validate = $('#'+formId).data('bootstrapValidator').validate();
	if(!validate.isValid()){ //如果校验不通过就返回
	    return;  
	}
	if("addForm1"==formId){
        var userPass1 = $('#'+formId).find("input[name='userPass1']").val();
        var userPass2 = $('#'+formId).find("input[name='userPass2']").val();
        if(userPass1!==userPass2){
            layer.alert("两次输入密码不一致！", {closeBtn: 0 });
		}
        $('#'+formId).find("input[name='uctUser.userPass']").val(userPass1.md5());
	}
	
	var index_submit = layer.confirm('您确定要保存信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		var result = submitForm(formId,tabId);
		if(result){
			layer.alert("提交成功！", {closeBtn: 0 });
      		mytools.closeModal("my_modal_add");
      		mytools.closeModal("my_modal_edit");
      		refresh();
		
    		
      		setToken();
    		if(!strUtil.isNull(tabId)){
      			$('.nav-tabs a[href=\"#'+tabId+'\"]').tab('show'); // Select tab by name 
      		}
	  	}
	});
	
 }
//提交表单数据
function submitForm(formId,tabId){
	var result;
	var index_load = layer.load(1, {shade: false});
	$.ajax({
	    type:'post',
	    url:common_submit_url,
	    data:$("#"+formId).serialize(),
	    async:false,
	    dataType:'json',
	    success: function(myData){ 
	     console.log(myData);
	        if(myData.flag=="T"){
	        	result = myData;
	    	}else{
	    		setToken();
	     		layer.alert(myData.msg);
	    	}
	        layer.close(index_load);
	  	},
	     error: function (e) {
		     layer.close(index_load);
     	} 
	});	
	return result;
}

//刷新
function refresh(){
	getTableData();
}
//设置token
function setToken(){
	$.ajax({
	    type:'get',
	    url:'${ctx}/sendPage/token?token=true',
	    dataType:'text',
	    success: function(myData){
	    	console.log(myData);
			$('.formToken').val(myData);
	  	}
	});	
}
//添加选用的管理员到，系统用户关系表中。
function addUserSysData(obj) {
	var userId = $(obj).attr('user-id');
    var userEname = $(obj).attr('user-ename');

    var paramData = {};
    paramData["modelTypes"]="i_uctUserSys";
    paramData["uctUserSys.sysNo"]=defSysEname;
    paramData["uctUserSys.userEname"]=userEname;
    paramData["uctUserSys.userId"]=userId;
    paramData["uctUserSys.orgId"]='${loginUser.orgId}';
    paramData["uctUserSys.deptId"]='${loginUser.deptId}';
    var index_load = layer.load(1, {shade: false});
    $.getJSON(common_list_url, {"modelTypes":"s_uctUserSys","uctUserSys.w_sysNo":defSysEname,"uctUserSys.w_userId":userId}, function (myData) {
        if(myData.total>0){
            layer.close(index_load);
            layer.msg("["+userEname+"]已被选用，不能重复选用！");
            return;
        }else{
            layer.close(index_load);
            var index_submit= layer.confirm('您确定要选用管理员['+userEname+']吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
			, function(){
                layer.close(index_submit);
                index_load = layer.load(1, {shade: false});
				var paramData = {};
				paramData["modelTypes"]="i_uctUserSys";
				paramData["uctUserSys.sysNo"]=defSysEname;
				paramData["uctUserSys.userEname"]=userEname;
				paramData["uctUserSys.userId"]=userId;
				paramData["uctUserSys.orgId"]='${loginUser.orgId}';
				paramData["uctUserSys.deptId"]='${loginUser.deptId}';

				$.getJSON(common_info_url, {"pageName":"uct-sys","formName":"searchForm","uctSys.sysEname":defSysEname}, function (myData) {
					console.log(myData);
					if(myData){
						var sysCname = myData.sysCname;
						var sysId = myData.sysId;
						paramData["uctUserSys.sysId"]=sysId;
						paramData["uctUserSys.sysName"]=sysCname;
						$.ajax({
							type:"post",
							url:common_submit_url,
							data: paramData,dataType:"json",
							success: function(myData){
								layer.close(index_load);
								var result = myData.flag;
								if(result=="T"){
									layer.msg("添加成功！");
									mytools.closeModal('my_modal_add');
									refresh();
								}else{
									layer.alert("添加失败！");
								}
							}
						});
					}
				});

			});
		}
    });
}

/**** Part 四、以下是自定义新增方法  ****/
//1.定义校验规则-定义
function setValidate(id){
	$(id).each(function(){
		$(this).bootstrapValidator({
		    feedbackIcons: {
		        valid: 'glyphicon glyphicon-ok',
		        invalid: 'glyphicon glyphicon-remove',
		        validating: 'glyphicon glyphicon-refresh'
		    },/** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
		 	fields:{
		 		/** 可自定义新增验证规则
		    	"uctUser.userEname":{
		    		 validators: {
		    			 regexp: {
		    				 regexp: /^[0-9]+$/,
		                      message: '只能是数字'
		                  }
		              }
		    	}
		    	**/
				}
		});
	});
}


</script>
</section>
<!-- Main end -->   
</div>
</div>
<!-- /.content-wrapper -->
<!-- foot start -->
<%@include file="/common/plateform/foot.jsp" %>
<!-- foot start -->
</body>
</html>














